<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>10_自定义JS对象</title>
</head>
<body>
<table border="1px">
    <caption>商品列表</caption>
    <tr>
        <th>商品名称</th>
        <th>商品价格</th>
        <th>商品库存</th>
    </tr>
</table>
<script>
    let productArr = [
        {title: '小米14', price: 8000, num: 500},
        {title: '苹果16', price: 10000, num: 400},
        {title: '魅族60', price: 2000, num: 600},
        {title: '魅族60', price: 2000, num: 600},
        {title: '魅族60', price: 2000, num: 600},
        {title: '魅族60', price: 2000, num: 600},
        {title: '魅族60', price: 2000, num: 600},
        {title: '魅族60', price: 2000, num: 600},
        {title: '华为70', price: 6700, num: 900}
    ];
    //1.获取表格元素
    let tableE = document.querySelector('table');
    //2.遍历商品数组
    for (let i = 0; i < productArr.length; i++) {
        //3.每遍历到一件商品,就需要创建1个tr与3个td
        let trE = document.createElement('tr');
        let titleTd = document.createElement('td');
        let priceTd = document.createElement('td');
        let numTd = document.createElement('td');
        //4.将数组中的值依次放入单元格中
        titleTd.innerHTML = productArr[i].title;
        priceTd.innerHTML = productArr[i].price;
        numTd.innerHTML = productArr[i].num;
        //5.将单元格放入tr中
        trE.append(titleTd, priceTd, numTd);
        //6.将tr放入table中
        tableE.append(trE);
    }


</script>
</body>
</html>